package com.syn.vr.control;

import android.content.Context;
import android.view.View;

import androidx.fragment.app.FragmentManager;

import com.gaoyi.basemodule.baseUtil.DensityUtil;
import com.gaoyi.basemodule.baseUtil.StringUtil;
import com.gaoyi.basemodule.basedialog.BaseFragmentDialog;
import com.syn.vr.databinding.ClearCacheDialogBinding;

public class ClearCacheDialog extends BaseFragmentDialog<ClearCacheDialogBinding> {

    private final String content;
    private final String onCancelText;
    private final String onConfirmText;
    private int confirmColor;
    private final View.OnClickListener onClickListener;

    public ClearCacheDialog(Context context, String content, String onCancelText, String onConfirmText, View.OnClickListener onClick) {
        super(context);
        this.content = content;
        this.onCancelText = onCancelText;
        this.onConfirmText = onConfirmText;
        this.onClickListener = onClick;
    }

    public ClearCacheDialog(Context context, String content, String onCancelText, String onConfirmText, int confirmColor, View.OnClickListener onClick) {
        super(context);
        this.content = content;
        this.onCancelText = onCancelText;
        this.onConfirmText = onConfirmText;
        this.onClickListener = onClick;
        this.confirmColor = confirmColor;
    }

    @Override
    protected void initView() {
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        if (confirmColor != 0) {
            mBinding.dialogBtnConfirm.setTextColor(confirmColor);
        }
        mBinding.dialogContent.setText(content);
        mBinding.dialogBtnCancel.setText(onCancelText);
        mBinding.dialogBtnConfirm.setText(onConfirmText);
        mBinding.dialogBtnCancel.setOnClickListener(v -> dismiss());
        mBinding.dialogBtnConfirm.setOnClickListener(v -> { onClickListener.onClick(v); dismiss(); });
    }

    @Override
    protected ClearCacheDialogBinding getViewBinding() {
        return ClearCacheDialogBinding.inflate(getLayoutInflater());
    }

    @Override
    protected String getShowTag() {
        return CENTER;
    }

    @Override
    protected int getWidth() {
        return DensityUtil.dp2px(280);
    }

    @Override
    public void show(FragmentManager fm) {
        if (!StringUtil.isEmpty(getShowTag())){
            fm.beginTransaction().remove(this).commit();
        }
        super.show(fm);
    }
}
